import { createRouter, createWebHashHistory } from 'vue-router'
import getEnv from '../utils/env'
import Loading from '../views/loading.vue'
import Notfound from '../views/notfound.vue'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: {
        path: '/auth'
      }
    },
    { path: '/notfound', meta: { title: '404' }, component: Notfound },
    {
      path: '/:pathMatch(.*)*',
      component: Loading
    }
  ]
})

router.beforeEach((...args) => {
  document.title = 'Loading...'
  args[2]()
})

router.afterEach((to) => {
  const name = getEnv('name')
  document.title = to.meta.title ? (to.meta.title as string) : name
})

export default router
